package com.web;

/**
 * Created by computer on 2016/12/10.
 */

import com.aop.LoginService;
import com.service.DemoService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * Created by caohongchen on 2016/3/16.
 * 处理请求的控制器，@Controller注入控制器的注解，spring还有好多注解，大家可以网上搜一下
 */
@Controller//这个不是url的一部分，直接适用requestMapping
public class DemoController {

    @Autowired
    public DemoService demoService;

    @Autowired
    public LoginService loginProxy;

//    @RequestMapping(value = {"/"}, method = {RequestMethod.GET})
//    public String ok(Model model) { //可以将参数直接绑定到这里  @RequestParam
//        return "ok";
//    }

    //url绑定，DispatcherServlet就是根据这个匹配控制器方法的
    @RequestMapping(value = "/sayHello", method = {RequestMethod.GET})
    public String sayHello(@RequestParam String name, Model model) { //可以将参数直接绑定到这里  @RequestParam
        System.out.println("-------------------------------------");
        model.addAttribute("name", name);//加入要返回的数据
        demoService.dService();
        loginProxy.login("sayHello");
        return "index2";
    }

    @RequestMapping(value = "/hello", method = {RequestMethod.GET})
    public String hello(Model model) { //可以将参数直接绑定到这里  @RequestParam
        System.out.println("-------------------------------------");
        loginProxy.login("HELLO");
        model.addAttribute("msg", "hello");//加入要返回的数据
        return "hello";
    }

    @RequestMapping(value = "/first", method = {RequestMethod.GET})
    public String first(Model model) { //可以将参数直接绑定到这里  @RequestParam
        model.addAttribute("msg", "first first first");//加入要返回的数据
        return "first";//我配置的视图解析器会去匹配hello.jsp
    }


    public void testUmP(){
        demoService.dService();
    }
}